package com.yanggu.spark.core.rdd.action

import org.apache.spark.{SparkConf, SparkContext}

//Action算子-Save
object RDD35_Save {

  def main(args: Array[String]): Unit = {

    //1. 创建sparkConf配置对象
    val sparkConf = new SparkConf().setMaster("local[*]").setAppName("spark")

    //2. 创建spark上下文对象
    val sparkContext = new SparkContext(sparkConf)

    //3. 从内存中创建RDD
    val value = sparkContext.makeRDD(List((1, "a"), (1, "a"), (1, "a"), (2, "b"), (3, "c"), (3, "c")))

    //4. save保存方法、一般是保存到文件
    //def saveAsTextFile(path: String): Unit
    //def saveAsObjectFile(path: String): Unit
    //def saveAsSequenceFile(path: String, codec: Option[Class[_ <: CompressionCodec]] = None): Unit

    //value.saveAsTextFile("out")
    //value.saveAsObjectFile("out")
    //此保存方法只能保存key-value类型的RDD
    value.saveAsSequenceFile("out")

    //6. 释放资源
    sparkContext.stop()
  }

}
